<template>
	<view class="NonCart">
		<view class="take-item" v-for="(item, index) in address">
			<view class="top" @tap="selectThisAddress(item)">
				<view class="user">
					<text>{{ item.name }}</text>
					<text class="padding-x-10">{{ item.tel }}</text>
				</view>
				<view class="address">{{ item.address }}-{{item.detail_address}}</view>
			</view>
			<view class="flex justify-between">
				<view class="bottom" @tap="setDefaultAddress(index)">
					<text class="iconfont icon-finish" style="font-size: 25rpx;"></text>
					设为默认地址
				</view>
				<view class="iconfont icon-shanchu" @tap="deleteAddress(index)"></view>
			</view>
			<view class="moren" v-if="item.defualt_true" >默认</view>
		</view>
		<view class="bottom-btn main-bg-color padding-y-20" style="color: #FFFFFF;text-align: center; width: 95%;" @tap="addAddress">新增收货地址</view>
	</view>
</template>

<script>
	import {mapState,mapMutations} from "vuex"
export default {
	
	data() {
		return {
			 prePage:"",
			 backType:0
		};
	},
	computed:{
		...mapState({
			address:state=>state.takeAddress.addressList
		})
	},
	onLoad(option) {
		console.log(option)
		if(option.param){
			this.backType=option.param;
		}
		// let pages = getCurrentPages();  //获取当前页面栈的实例
		// let page = (pages[pages.length - 1]).route;  //获取当前页面的路由
		// // pages.forEach(v=>{
		// // 	console.log(v.route)
		// // })
		//  this.prePage=(pages[0]).route;//获取第一个页面的路由
		
	},  
	methods: {
		...mapMutations({
			setDefaultAddress:"setDefaultAddress",
			deleteAddress:"deleteAddress"
		}),
		 
		addAddress() {
			uni.redirectTo({
				url: '../take-address-update/take-address-update?param='+this.backType
			});
		},
		// 选中这个收获地址
		selectThisAddress(item){
			if(this.backType==0){
				uni.redirectTo({
					url:"../goods-detail/goods-detail?param="+JSON.stringify(item)
				})
			}else{
				// 页面之间的通讯。用来选择收获地址
				uni.$emit('chooseAddress',item);
				
				uni.redirectTo({
					url:"../order-pay/order-pay?param="+JSON.stringify(item)
				})
			}
			
		} 
	}
};
</script>

<style lang="less">
body {
	background-color: #f7f7f7;
}
.take-item {
	margin: 20rpx;
	border-radius: 10rpx;
	background-color: #ffffff;
	position: relative;
	overflow: hidden;
	.top {
		border-bottom: 1rpx solid #f1f1f1;
		overflow: hidden;

		.address {
			font-size: 25rpx;
			padding-bottom: 10rpx;
		}
	}
	.top,
	.bottom {
		padding-left: 20rpx;
	}
	.bottom {
		font-size: 25rpx;
		color: #cccccc;
	}
	.user {
		padding: 10rpx 0rpx;
	}
	// 倾斜的默认，父元素要设置overflow: hidden;
	.moren {
		font-size: 20rpx;
		color: #ffffff;
		padding: 0 30rpx;
		transform: rotate(45deg);
		background-color: #fd6801;
		position: absolute;
		top: 9rpx;
		right: -24rpx;
	}
}

.NonCart {
	height: 100%;
	position: relative;
}
.bottom-btn {
	margin-top: 50rpx;
	margin-bottom: 50rpx;
	position: absolute;
	left: 50%;

	border-radius: 10rpx;
	transform: translateX(-50%);
}
</style>
